home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_360 / uucp / uucp0.lzh / src / news / postnews.c.old < prev    next >
Text File  |  1990-05-17  |  4KB  |  222 lines

  1.  
  2. /*
  3.  *  PostNews.c
  4.  *
  5.  *  Copyright 1988 by William Loftus.  All rights reserved.
  6.  *
  7.  *  Version 0.60 Beta
  8.  *
  9.  *  $Header: Beta:src/uucp/src/News060/postnews.c,v 1.1 90/02/02 11:44:07 dillon Exp Locker: dillon $
  10.  */
  11.  
  12. #include <time.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include "log.h"
  16. #include "version.h"
  17.  
  18. IDENT(".02");
  19.  
  20. char *UserName;
  21. char *NodeName;
  22. char *RealName;
  23. char *NewsEditor;
  24. char *DomainName;
  25. char to_buf[128];
  26. char grp_buf[128];
  27. char dist_buf[128];
  28. char subject_buf[128];
  29. char *temp_file_name;
  30.  
  31. int seq;
  32.  
  33. char *NewsFeed;
  34.  
  35. char cmd[128];
  36. char path[128];
  37. char signature[121];
  38.  
  39. void read_ctl();
  40. void GetTo();
  41. void GetDist();
  42. void GetSubject();
  43. void GetMessage();
  44. void BuildRnews();
  45. void Signature();
  46. void PromptGet();
  47. char *TmpFileName();
  48. char *FindConfig();
  49.  
  50. void
  51. errormsg (msg, ...)
  52. char *msg;
  53. {
  54.     printf(msg);
  55. }
  56.  
  57.  
  58. void
  59. main()
  60. {
  61.     temp_file_name = TmpFileName(MakeConfigPath(UUSPOOL, "news"));
  62.  
  63.     LogProgram = "PostNews";
  64.  
  65.     UserName = FindConfig("UserName");
  66.     NodeName = FindConfig("NodeName");
  67.     NewsFeed = FindConfig("NewsFeed");
  68.     NewsEditor=FindConfig("NewsEditor");
  69.     RealName = FindConfig("RealName");
  70.     DomainName=FindConfig("DomainName");
  71.  
  72.     if (UserName == NULL || NodeName == NULL || NewsFeed == NULL ||
  73.     NewsEditor==NULL || RealName == NULL || DomainName == NULL)
  74.     {
  75.     printf("UULIB:Config incomplete, missing one or more of:\n");
  76.     printf("    UserName, NodeName, DomainName, NewsFeed, NewsEditor, RealName\n");
  77.     exit(1);
  78.     }
  79.  
  80.     GetTo();
  81.     GetDist();
  82.     GetSubject();
  83.     GetMessage();
  84.     BuildRnews();
  85. }
  86.  
  87. void
  88. GetTo()
  89. {
  90.     PromptGet("Newsgroup(s): ", 0, grp_buf, sizeof(grp_buf), stdin);
  91. }
  92.  
  93. void
  94. GetDist()
  95. {
  96.     FILE *fd;
  97.     char  buf[128];
  98.  
  99.     if (!(fd = fopen(MakeConfigPath(UULIB, "news.distribution"), "r"))) {
  100.     errormsg("Can't Find news.distribution file");
  101.     exit(3);
  102.     }
  103.  
  104.     while (fgets(buf, sizeof buf, fd)) {
  105.     printf("%s", buf);
  106.     }
  107.  
  108.     PromptGet("Distribution: ", 0, dist_buf, sizeof(dist_buf), stdin);
  109. }
  110.  
  111. void
  112. GetSubject()
  113. {
  114.     PromptGet("Subject: ", 1, subject_buf, sizeof(subject_buf), stdin);
  115. }
  116.  
  117. void
  118. GetMessage()
  119. {
  120.     FILE *fp;
  121.     time_t t;
  122.  
  123.     seq = GetSequence(4);
  124.  
  125.     fp = fopen(temp_file_name, "w");
  126.  
  127.     if (fp) {
  128.     time(&t);
  129.     fprintf(fp,"Relay-Version: X-AmigaNEWS version 0.60 BETA; site %s%s\n", NodeName, DomainName);
  130.     fprintf(fp,"Posting-Version: X-AmigaNEWS version 0.60 BETA; site %s%s\n", NodeName, DomainName);
  131.     fprintf(fp,"Path: %s!%s\n", NodeName, UserName);
  132.     fprintf(fp,"From: %s@%s%s (%s)\n", UserName, NodeName, DomainName, RealName);
  133.     fprintf(fp,"Newsgroups: %s", grp_buf);
  134.     fprintf(fp,"Subject: %s", subject_buf);
  135.     fprintf(fp,"Message-Id: <%05d.AA%05d@%s%s>\n", seq, seq, NodeName, DomainName);
  136.     fprintf(fp,"Date: %s", ctime(&t));
  137.     fprintf(fp,"Followup-To: %s", grp_buf);
  138.     fprintf(fp,"Expires: \n");
  139.     fprintf(fp,"Keywords: \n");
  140.     fprintf(fp,"Distribution: %s\n\n", dist_buf);
  141.  
  142.     fclose(fp);
  143.     } else {
  144.     errormsg("Can't open temp file %s\n", temp_file_name);
  145.     exit(1);
  146.     }
  147.  
  148.     sprintf(cmd,"%s %s", NewsEditor, temp_file_name);
  149.     system(cmd);
  150.  
  151.     printf("Append .signature file? [y/n] ");
  152.     fgets(signature, sizeof signature, stdin);
  153.     if ((signature[0] | 0x20) != 'n') {
  154.     Signature();
  155.     printf(".signature file appended.\n");
  156.     }
  157. }
  158.  
  159. void
  160. BuildRnews()
  161. {
  162.     NewsFeed[7] = '\0';
  163.  
  164.     sprintf(cmd, "UUX %s \"%s!rnews\"", temp_file_name, NewsFeed);
  165.     system(cmd);
  166.     remove(temp_file_name);
  167. }
  168.  
  169. /*
  170.  * Read the control file and grab a few parameters.
  171.  */
  172.  
  173. void
  174. Signature()
  175. {
  176.     FILE *fp;
  177.     FILE *sf;
  178.     char buff[128];
  179.  
  180.     fp = fopen(temp_file_name, "a");  /* should already exist!! */
  181.  
  182.     if (!fp) {
  183.     errormsg("Can't open temp file--%s\n", temp_file_name);
  184.     exit(1);
  185.     }
  186.  
  187.     fprintf(fp, "\n--\n");
  188.  
  189.     sf = fopen(MakeConfigPath(UULIB, ".signature"), "r");
  190.  
  191.     if (sf) {
  192.     while (NULL != fgets(buff, sizeof buff, sf)) {
  193.         fprintf(fp, "%s", buff);
  194.     }
  195.     fclose(sf);
  196.     } else {
  197.     errormsg("Can't open .signature file\n");
  198.     }
  199.     fclose(fp);
  200. }
  201.  
  202. void
  203. PromptGet(prompt, loop, buf, bufsize, fin)
  204. char *prompt;
  205. char *buf;
  206. FILE *fin;
  207. {
  208.     short i;
  209.  
  210.     do {
  211.     printf("%s", prompt);
  212.     fflush(stdout);
  213.     if (fgets(buf, bufsize, fin) == NULL)
  214.         break;
  215.     for (i = 0; buf[i] == ' ' || buf[i] == 9; ++i);
  216.     if (buf[i] != '\n')
  217.         break;
  218.     } while (loop);
  219. }
  220.  
  221.  
  222.